<template>
  <div class="w-full h-full" ref="chartRef"></div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';

  export default defineComponent({
    name: 'WorkbenchChart',
  });
</script>

<script lang="ts" setup>
  import { ref, onMounted, onUnmounted } from 'vue';
  import * as echarts from 'echarts';
  import { EChartsType, EChartsOption } from 'echarts';

  const props = defineProps<{
    option: EChartsOption;
  }>();

  const chartRef = ref();

  let chart: EChartsType | null = null;

  const resize = () => {
    (chart as EChartsType).resize();
  };

  onMounted(() => {
    chart = echarts.init(chartRef.value);
    chart.setOption(props.option);
    window.addEventListener('resize', resize);
  });

  onUnmounted(() => {
    window.removeEventListener('resize', resize);
  });
</script>
